

#include <string>
#include "../src/URL.cpp"
//#include "../src/URLDownloader.cpp"
#include "../src/URLHistory.cpp"
#include "../src/URLQueue.cpp"
#include "../src/URLValidator.cpp"
#include "../src/urlResolver.cpp"

	string a1 = "http://www.cnn.com";
	string a2 = "http://www.CNN.com";
	string a3 = "http://www.byu.edu/INDEX.html";
	string a4 = "http://www.byu.edu/index.html";
	string b1 = "http://www.cnn.com", b2 ="http://www.CNN.com" , b3 ="http://www.byu.edu/" , b4="http://www.byu.edu/";
	string t1 = "",t2 = "", t3 = "INDEX.html", t4="index.html";

	extern URL array[];
	extern string s1,s2,s3,s4,s5,s6,s7,s8;
	extern void iniValues();

	int URLTests(){
		URL u1temp(&a1), u2temp(&a2),  u4temp(&a4);
		URL *u3temp=new URL(&a3);
		if(u1temp.getBaseAddr().compare(b1)!=0 ||u2temp.getBaseAddr().compare(b2)!=0 ||u3temp->getBaseAddr().compare(b3)!=0||u4temp.getBaseAddr().compare(b4)!=0)
		{
			return 1;    //Constructor parsing base addr incorrectly
		}
		if(u1temp.getPath().compare(t1)!=0 ||u2temp.getPath().compare(t2)!=0||u3temp->getPath().compare(t3)!=0||u4temp.getPath().compare(t4)!=0)
			return 2;	//Constructor parsing path incorrectly
		if(u1temp.compare(u2temp)!=0 || u2temp.compare(*u3temp)==0 || u3temp->compare(u4temp)==0){
			return 3;	//comparing incorrect
		}
		string temp = u1temp.getBaseAddr();
		string temp2 = u4temp.getPath();
		if(temp.compare(b1)!=0)
			return 4; //Memory Issue
		u1temp= *u3temp;
		u2temp= *u3temp;

		if (u1temp.compare(u2temp)!=0)
			return 5; // opperator = issue
		delete u3temp;
		if (u1temp.getPath().compare(t3)!=0)
			return 6;  //opperator = issue after delete

		URL u5temp(u4temp);
		if (u5temp.compare(u4temp)!=0)
			return 7; // copy constructor issue
		u4temp=u1temp;
		if (u5temp.getPath().compare(t4)!=0)
			return 8;  //copy constructor issue after delete

		return 0;
	}


	int URLValidatorTests(){
			iniValues();
			URLValidator *v1,*v2,*v3;
			string stest1("www.test.com");
			URL *utest1,*utest2;
			try{
				try{

					v1 = new URLValidator(&stest1);
					return 1; //Invalid URL not caught
				}
				catch(InvalidSiteException *e){
					delete v1;
				}
				v1 = new URLValidator(&s1);
				//cout << v1->getBaseAddr();
//				if (v1->validateURL(&s2)==NULL || v1->validateURL(&s3)==NULL )
//					return 2; //Did not accept vaild URL
//				utest1=v1->validateURL(&s2);
//				utest2=v1->validateURL(&s3);
//				//check if querry and frag were stripped
//
//				if(v1->validateURL(&s4)!=NULL)
//					return 3; //Out of Scope URL accepted
//				utest1=v1->validateURL(&s4);
				//cout << utest1 << "here";

			}
			catch(...){
				return 6; //Something Broke
			}
			return 0;
		}

	int URLHistoryTests(){
		iniValues();

		URLHistory hist;

		if (!hist.add(array[1]) ||	hist.add(array[1])||!hist.add(array[2])||!hist.add(array[3]))
			return 1; //adding incorrect
		if(hist.contains(array[4])|| !hist.contains(array[3]))
			return 2; //contains inncorrect

		return 0;
	}

	int URLQueueTests(){
		iniValues();
		URLQueue queue;
		queue.push(array[1]);
		queue.push(array[2]);
		queue.push(array[1]);
		queue.push(array[3]);
		if(queue.isEmpty())
			return 1;	//not adding
		if(queue.pop()->compare(array[1])!=0 || queue.pop()->compare(array[1])==0||queue.pop()->compare(array[3])!=0)
			return 2; //Pop then compare wrong
		if(!queue.isEmpty())
			return 3; //queue not empty

		return 0;
	}
